#!/bin/bash
#version: 1.0.0
#pidgin-dep-easyinstaller: this script creates a build environment for pidgin, to build on windows using cygwin
#Copyright (C) 2010  Constantin Wenger aka SpeedProg
#This program is free software;
#you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation;
#either version 3 of the License, or (at your option) any later version.
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#See the GNU General Public License for more details.
#You should have received a copy of the GNU General Public License along with this program;
#if not, see <http://www.gnu.org/licenses/>.
echo "start downloading builddependeces"
wget "http://pidgin-dep-easyinstaller.googlecode.com/files/win32-dev.tar.gz"
echo "extract dependeces, please wait..."
tar xfz win32-dev.tar.gz
echo "getting NSIS installer"
wget "http://garr.dl.sourceforge.net/project/nsis/NSIS%202/2.46/nsis-2.46-setup.exe"
echo "please open nsis-2.46-setup.exe in your DEV folder and NSIS to your harddrive"
echo "please enter the location you installed NSIS to (use / for seperating folders)"
echo "example: C:/Program Files (x86)/NSIS"
read NSIS_DIR
NSIS_DIR=$(echo $NSIS_DIR | tr '[:upper:]' '[:lower:]')
regex="([a-z]):/(.*)"
if [[ $NSIS_DIR =~ $regex ]]; then
	echo "/cygdrive/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}" >> "$HOME/.bashrc"
	wget "http://pidgin-dep-easyinstaller.googlecode.com/files/nsisunz-dll-1_0.zip"
	unzip nsisunz-dll-1_0.zip -d "$NSIS_DIR/plugins"
else
	echo "NISI could not be automaticaly added to the PATH, please do it manualy."
	echo "Open .bashrc (inside $HOME) with a texteditor an add to the end of the file:"
	echo "PATH=\"/cygdrive/DRIVE/RESTOFPATH\":PATH"
	echo "replace  DRIVE by the letter of the drive you installed NSIS on"
	echo "replace RESTOFPATH by the rest of the path to NSIS folder"
	echo "for C:\Program Files (x86)\NSIS it would be PATH=\"/cygdrive/c/Program Files (x86)/NSIS\":PATH"
	echo "Dowloading nsisunz plugin"
	wget "http://pidgin-dep-easyinstaller.googlecode.com/files/nsisunz-dll-1_0.zip"
	echo "Open nsisunz-dll-1_0.zip, and extract nsisunz.dll into the Plugins directory of your NSIS installation."
fi
echo "creating dir to load monotone database into"
mkdir mtndb
echo "changing to mtndb"
cd mtndb
echo "downloading static pidgin monotone database from: http://developer.pidgin.im/static/pidgin.mtn.bz2"
wget "http://developer.pidgin.im/static/pidgin.mtn.bz2"
echo "extracting monotone database"
bzip2 -d pidgin.mtn.bz2
echo "changing back to dev-root"
cd ..
echo "migrating database"
mtn -d ./mtndb/pidgin.mtn db migrate
echo "getting changes from: mtn.pidgin.im \"im.pidgin.*\""
mtn -d ./mtndb/pidgin.mtn pull --set-default mtn.pidgin.im "im.pidgin.*"
echo "extracting lasest revision to pidgin-2.7.0"
mtn -d ./mtndb/pidgin.mtn co -b im.pidgin.pidgin pidgin-2.7.0
rm nsisunz-dll-1_0.zip
rm win32-dev.tar.gz
rm nsis-2.46-setup.exe
echo "you can now got to pidgin-2.7.0 and type \"make -f Makefile.wingw install\" to build pidgin :)"
echo "or \"make -f Makefile.wingw installer\" to build the pidginistallers"
